package com.huawei.petSystemdemo.data;

import android.location.Address;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huawei.petSystemdemo.bean.Adress;
import com.huawei.petSystemdemo.bean.Order;
import com.huawei.petSystemdemo.utils.MyRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class AdressRepository extends BaseRepository {

    public static void getAll(int user_id, Consumer<List<Adress>> callback) {
        Map<String, Object> res = new HashMap<>();
        res.put("user_id", user_id);
        MyRequest.get("/shopadress/getAll", res, json -> {
            JSONObject obj = JSON.parseObject(json);
            boolean success = obj.getBoolean("success");
            if (success)
            {
                List<Adress> adressList = obj.getJSONArray("data").toJavaList(Adress.class);
                if (callback != null)
                    callback.accept(adressList);
            }
            else
            {

            }
        });
    }

    public static void getById(int addId, Consumer<Adress> callback) {
        Map<String, Object> res = new HashMap<>();
        res.put("addId", addId);
        MyRequest.get("/shopadress/getAddById", res, new BeanDataConsumer<Adress>(Adress.class, callback, null));
    }
}
